package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.StudyVideo;
import com.dingreading.cloud.admin.entity.StudyVideoExpire;
import com.dingreading.cloud.admin.entity.table.StudyVideoExpireTableDef;
import com.dingreading.cloud.admin.mapper.StudyVideoExpireMapper;
import com.dingreading.cloud.admin.service.StudyVideoExpireService;
import com.mybatisflex.core.update.UpdateChain;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2025-09-18
 */
@Service
public class StudyVideoExpireServiceImpl extends BaseServiceImpl<StudyVideoExpireMapper, StudyVideoExpire, StudyVideoExpireTableDef> implements StudyVideoExpireService {

    @Override
    protected StudyVideoExpireTableDef getTable() {
        return StudyVideoExpireTableDef.studyVideoExpire;
    }

    @Override
    public StudyVideoExpire getByUid(String uid) {
        return getMapper().selectOneByCondition(table.uid.eq(uid));
    }

    @Override
    public boolean updateEnabled(String videoExpireUid, Integer enabled, String headStaffUid, String headStaffName) {
        return UpdateChain.of(StudyVideo.class)
                .set(table.enabled, enabled)
                .set(table.lastStaffUid, headStaffUid)
                .set(table.lastStaffName, headStaffName)
                .where(table.uid.eq(videoExpireUid))
                .update();
    }

    @Override
    public boolean existsByVideoUid(String videoUid) {
        return exists(table.videoUid.eq(videoUid));
    }

    @Override
    public List<StudyVideoExpire> listByVideoUid(String videoUid) {
        return getMapper().selectListByCondition(table.videoUid.eq(videoUid));
    }

    @Override
    public int deleteByUid(String uid) {
        return getMapper().deleteByCondition(table.uid.eq(uid));
    }
}
